Skip to main content

Swig 使用语法问题

js 代码块包裹 {% autoescape 'js' %} {% endautoescape %}

问题描述:在 js 代码块,一些特殊符号会被输出成转义字符, 如"<"、">"、"&"等字符,会变"&lt;"、"&gt;"、"&amp;"等的转义字符。

解决:{% autoescape 'js' %}<script>{{输出变量}} </script>{% endautoescape %} 或者 `{% autoescape false %}

autoescape tag 用法说明